<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="noticeDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='noticeDetail.heading'/>"/>
    <sx:head />
</head>

<c:set var="delObject" scope="request"><fmt:message key="noticeList.notice"/></c:set>
<script type="text/javascript">var msgDelConfirm =
   "<fmt:message key="delete.confirm"><fmt:param value="${delObject}"/></fmt:message>";
   
   $(document).ready(function() {
	$('#newnoticeattachment').click(function(){
			 var form=$('</p><input type="file" name="upload">');
            $("#input").append(form);
	});
	});
</script>

<div class="span2">
    <h2><fmt:message key="noticeDetail.heading"/></h2>
    <fmt:message key="noticeDetail.message"/>
</div>

<div class="span7">
    <s:form id="noticeForm" action="saveNotice" method="post" validate="true" cssClass="well form-horizontal"  enctype="multipart/form-data">
        <s:hidden key="notice.id"/>
        <fieldset class="control-group">
    	<label class="control-label"> PostDate: </label>
    	<div class="controls">
    	<sx:datetimepicker  required="true" name="notice.postDate" value="notice.postDate"/>
    	<sx:datetimepicker  required="true" name="hourformat" value="hourformat" type="time"/>
    	</div>
		</fieldset>
		<s:select required = "true" name="notice.systemuser.id" list="systemuserList" listKey="id" listValue="name"   label="Systemusers"></s:select>		
    	<c:if test="${not empty notice.id}">
    	<fieldset class="control-group">
    	<label class="control-label">  </label>
    	<div class="controls">
    			<a href="editSystemuser?id=<c:out value="${notice.systemuser.id}"/>">View <c:out value="${notice.systemuser.name}"/></a>
    	</div>
		</fieldset>
		 </c:if>
        <s:textfield key="notice.title" required="false" maxlength="100" />
        <s:textfield key="notice.viewTimes" required="true" maxlength="255" />
        <s:textarea key="notice.content" required="true" maxlength="255" id="Content"/>       
		<s:select required = "true" name="notice.department.id" list="departmentList" listKey="id" listValue="name"   label="Department"></s:select>		
    	<c:if test="${not empty notice.id}">
    	<fieldset class="control-group">
    	<label class="control-label">  </label>
    	<div class="controls">
    			<a href="editDepartment?id=<c:out value="${notice.department.id}"/>">View <c:out value="${notice.department.name}"/></a>
    	</div>
		</fieldset>
		 </c:if>

        <div id="actions" class="form-actions">
            <s:submit type="button" cssClass="btn btn-primary" method="save" key="button.save" theme="simple">
                <i class="icon-ok icon-white"></i> <fmt:message key="button.save"/>
            </s:submit>
            <c:if test="${not empty notice.id}">
                <s:submit type="button" cssClass="btn btn-warning" method="delete" key="button.delete"
                    onclick="return confirmMessage(msgDelConfirm)" theme="simple">
                    <i class="icon-trash icon-white"></i> <fmt:message key="button.delete"/>
                </s:submit>
            </c:if>
         	<c:if test="${empty notice.id}">
                <button type="button" class="btn btn-primary" id="newnoticeattachment">Add attachement</button> 
            </c:if>
            <s:submit type="button" cssClass="btn" method="cancel" key="button.cancel" theme="simple">
                <i class="icon-remove"></i> <fmt:message key="button.cancel"/>
            </s:submit>
        </div>
        <c:if test="${empty notice.id}">
	        <fieldset class="control-group">
	    	<label class="control-label">Attachement</label>
	    	<div class="controls" id="input">
			        <input type="file" name="upload">
	    	</div>
			</fieldset>
		</c:if>
    </s:form>
    
    
    <c:if test="${not empty notice.id}">
  	<h2>Attachments</h2>
    <s:form id="attachmentForm" action="addAttachment" method="post" validate="true" cssClass="well form-horizontal" enctype="multipart/form-data">
        <s:hidden key="notice.id"/>
     	<s:file label="Add attachment" name="attachmentfile" />
     	 <div id="actions" class="form-actions">
        <s:submit type="button" cssClass="btn btn-primary" method="addAttachment" key="button.save" theme="simple">
            <i class="icon-ok icon-white"></i> add
        </s:submit>
        </div>
	</s:form>
    <display:table name="notice.attachements" class="table table-condensed table-striped table-hover" requestURI="" id="attachementList" export="true" pagesize="25">
        <display:column property="id" sortable="true" href="editAttachement" media="html"
            paramId="id" paramProperty="id" titleKey="attachement.id"/>
        <display:column property="id" media="csv excel xml pdf" titleKey="attachement.id" />
        <display:column property="filename" sortable="true" titleKey="attachement.filename" href="attachmentdownload"
      	  paramId="attachmentid" paramProperty="id"/>
	      <display:column>
	       <s:form id="deleteAttachmentForm" action="deleteAttachment" method="post" validate="true">
			    <s:hidden key="notice.id"/>
			    <s:hidden value="%{#attr.attachementList.id}" name="attachmentid"/>
			    <s:submit type="button" cssClass="btn btn-primary" method="deleteAttachment" key="button.delete" theme="simple">
			        <i class="icon-ok icon-white"></i> delete
			    </s:submit>
			</s:form>
         </display:column>
        <display:setProperty name="paging.banner.item_name"><fmt:message key="attachementList.attachement"/></display:setProperty>
        <display:setProperty name="paging.banner.items_name"><fmt:message key="attachementList.attachements"/></display:setProperty>

        <display:setProperty name="export.excel.filename"><fmt:message key="attachementList.title"/>.xls</display:setProperty>
        <display:setProperty name="export.csv.filename"><fmt:message key="attachementList.title"/>.csv</display:setProperty>
        <display:setProperty name="export.pdf.filename"><fmt:message key="attachementList.title"/>.pdf</display:setProperty>
    </display:table>
    </c:if>
       <% 
		CKEditorConfig settings = new CKEditorConfig();
		settings.addConfigValue("width","500");
		settings.addConfigValue("height","500");
		%>
   <ckeditor:replace  basePath="/ckeditor/" replace ="Content" config="<%=settings %>"/> 
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $("input[type='text']:visible:enabled:first", document.forms['noticeForm']).focus();
    });
</script>
